from selenium.webdriver.common.by import By

from Common.Utils import blog_driver
from Common.FormHelper import FormHelper
from LoginTest import Login

class MyProject:
    url=""
    driver=""

    def __init__(self):
        self.url="http://49.235.61.184:8080/project"
        self.driver=blog_driver.driver
        self.form = FormHelper(self.driver)
        # 公共自动登录方法，未登录时执行Login().LoginSuTest
        # self.form.auto_login(self.url, login_func=lambda: Login().LoginSuTest())
        self.driver.get(self.url)

        # 检测页面元素
    def pageElements(self):
        elememts_check = {"#sk-layout > div > div > section > div.ant-pro-layout-container > main > div > div.ant-page-header.ant-pro-page-container-warp-page-header.ant-pro-page-container-warp-page-header.ant-page-header-has-breadcrumb.ant-page-header-ghost > div.ant-page-header-heading > div > span"}
        blog_driver.GetScreeShot()
        if self.form.are_all_elements_present(elememts_check, 5):
            print("元素都存在")
        else:
            print("元素存在有问题")

    #测试新增问卷调查
    def AddnewTest(self):
        self.form.click("#sk-layout > div > div > section > div.ant-pro-layout-container > main > div > div.ant-page-header.ant-pro-page-container-warp-page-header.ant-pro-page-container-warp-page-header.ant-page-header-has-breadcrumb.ant-page-header-ghost > div.ant-page-header-heading > span > div > div > button")
        #等待问卷调查出现并截图
        self.form.screenshot_after_presence("body > div:nth-child(7) > div > div > ul > li:nth-child(1) > span")
        self.form.click("body > div:nth-child(7) > div > div > ul > li:nth-child(1) > span")
        #检测跳转成功并截图
        self.form.screenshot_after_presence("#editorContent > div > div > div.header > div.header-content > div.sc-aXZVg.LyTMt.title.quill-container.not-focus > div > pre > div.ql-editor > p")
        #新增
        self.form.fill_fields({"#editorContent > div > div > div.header > div.header-content > div.sc-aXZVg.LyTMt.title.quill-container.not-focus > div > pre > div.ql-editor":"add"})
        #保存
        self.driver.find_element(By.CSS_SELECTOR,"#editor > div.survey-main-panel > div.survey-main-panel-toolbar > div:nth-child(2) > div > button.ant-btn.ant-btn-primary.ant-btn-sm").click()
        blog_driver.GetScreeShot()
        self.driver.back()
        self.driver.back()

        #检查问卷是否新增成功
        self.form.verify_error_message("#sk-layout > div > div > section > div.ant-pro-layout-container > main > div > div.ant-pro-grid-content > div > div > div > div.ant-list.ant-list-split.ant-list-grid.survey-home-content > div > div > div > div > div > div > div > div > div > div.card-header > span.survey-title","add")
        blog_driver.GetScreeShot()


    #检测项目查询功能
    def CheckTest(self):
        self.form.fill_fields({"#sk-layout > div > div > section > div.ant-pro-layout-container > main > div > div.ant-page-header.ant-pro-page-container-warp-page-header.ant-pro-page-container-warp-page-header.ant-page-header-has-breadcrumb.ant-page-header-ghost > div.ant-page-header-content > div > div > div > div > div > div > div > span > span > input":"add"})
        blog_driver.GetScreeShot()
        self.form.click("#sk-layout > div > div > section > div.ant-pro-layout-container > main > div > div.ant-page-header.ant-pro-page-container-warp-page-header.ant-pro-page-container-warp-page-header.ant-page-header-has-breadcrumb.ant-page-header-ghost > div.ant-page-header-content > div > div > div > div > div > div > div > span > span > span > button")
        blog_driver.GetScreeShot()
        self.form.verify_error_message("#sk-layout > div > div > section > div.ant-pro-layout-container > main > div > div.ant-pro-grid-content > div > div > div > div.ant-list.ant-list-split.ant-list-grid.survey-home-content > div > div > div > div > div > div > div > div > div > div.card-header > span.survey-title","add")










# project=MyProject()
# project.AddnewTest()
# project.CheckTest()